%{
    // Eval fields tags
    def fieldsHandler = [:]
    if(_body) {
        _body.setProperty('fieldsHandler', fieldsHandler);
}%
        #{doBody as:'skip' /}
%{
    }
}%
        
%{ 
	_fields = [] 
	_caller.type.fields*.name.each{fieldName->
		if ( !("_").equals(fieldName[0]) ) {
			_fields.add(fieldName)
		}
	}
}%



<div class="am-u-sm-12">
	<table class="am-table am-table-striped am-table-hover table-main">
		<thead>
			<tr>
            	 %{ if(_fields) { }%
            	 	<th>
						<input type="checkbox">            	 		
            	 	</th>
		            %{ _fields.each() { }%
		            <th>
		                %{ if(!_sort || _sort.contains(it)) { }%
		                <a class="${_caller.orderBy == it ? (_caller.order == 'DESC' ? 'crudSortedDesc' : 'crudSortedAsc') : ''}" href="@{list().remove('page').add('search', params.search).add('orderBy', it).add('order', (_caller.orderBy == it && _caller.order == 'ASC' ? 'DESC' : 'ASC'))}">
		                    &{it}
		                </a>
		                %{ } else { }%
		                    &{it}
		                %{ } }%
		            </th>
		            %{ } }%
		        %{ } else { }%
		            <th>
		                <a class="${_caller.order == 'DESC' ? 'crudSortedDesc' : 'crudSortedAsc'}" href="@{list().remove('page').add('search', params.search).add('order', (_caller.order == 'DESC' ? 'ASC' : 'DESC'))}">
		                    &{_caller.type.name} 
		                </a>
		            </th>
		        %{ } }%
		     
				<th class="table-set">操作</th>
			</tr>
		</thead>
		<tbody>
		    %{ _caller.objects.eachWithIndex() { object, k -> }%
		    <tr class="${k % 2 ? 'even' : 'odd'}">
		    	<td><input type="checkbox"></td>
		        %{ if(_fields) { }%
		            %{ _fields.eachWithIndex() { field, i -> }%
		            <td>
		                %{ if(fieldsHandler[field]) { }%
		                    %{
		                        def handler = fieldsHandler[field];
		                        handler.setProperty('object', object);
		                    }%
		                    #{doBody body:handler /}
		                    %{
		                        handler.setProperty('object', null);
		                    }%
		                %{ } else { }%
		                    %{ if(i == 0) { }%
		                        ${object[field]?.toString()?.escape()?.raw() ?: '(no value)'}
		                    %{ } else { }%
		                        %{ if(_caller.type.getField(field).type == 'file') { }%
		                            %{ if(object[field]) { }%
		                                <a class="currentAttachment" href="@{attachment(object.id, field)}">${object[field].filename} (${object[field].get().size().formatSize()})</a>
		                             %{ } else { }%
		                                
		                             %{ } }%
		                        %{ } else { }%
		                            ${object[field]?.escape()?.raw()}
		                        %{ } }%
		                    %{ } }%
		                %{ } }%
		            </td>
		            %{ } }%
		     		<td>
						<div class="am-btn-toolbar">
							<div class="am-btn-group am-btn-group-xs">
								<table>
									<tr>
										<td>
											<button
												class="am-btn am-btn-default am-btn-xs am-text-secondary" 
												onclick="window.location.href='@{show(object._key())}'">
												<span class="am-icon-pencil-square-o">
													编辑
												</span> 
											</button>
										</td>
										<td>
											#{form @delete(object._key())}
												<button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
													<span class="am-icon-trash-o"></span> 删除
												</button>
										    #{/form}
											</td>
									</tr>
								</table>
							</div>
						</div>
					</td>
		        %{ } else { }%
		            %{ if(fieldsHandler['default']) { }%
		                %{
		                    def handler = fieldsHandler['default'];
		                    handler.setProperty('object', object);
		                }%
		                #{doBody body:handler /}
		            %{ } else { }%
		                <td>
		                    <a href="@{show(object._key())}">${object.toString()?.escape()?.raw() ?: '(no value)'}</a>
		                </td>
		            %{ } }%
		        %{ } }%
		    </tr>
		    %{ } }%
		
		</tbody>
	</table>
	<div class="am-cf">

		<div class="am-fr">
            <ul class="am-pagination tpl-pagination">
                <li class="am-disabled"><a href="#">«</a></li>
                <li class="am-active"><a href="#">1</a></li>
                <li><a href="#">2</a></li>
                <li><a href="#">3</a></li>
                <li><a href="#">4</a></li>
                <li><a href="#">5</a></li>
                <li><a href="#">»</a></li>
            </ul>
        </div>
	</div>
	<hr>
</div>